package com.zk.babala.presenter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zk.babala.R;

import java.util.List;

/**
 * @Author: zhangke
 * @Date: 2025/8/28 9:33
 */
public class SearchHistoryAdapter extends BaseAdapter {
    private Context context;
    private List<String> searchHistoryList;
    private LayoutInflater inflater;

    public SearchHistoryAdapter(Context context, List<String> searchHistoryList) {
        this.context = context;
        this.searchHistoryList = searchHistoryList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return searchHistoryList.size();
    }

    @Override
    public Object getItem(int position) {
        return searchHistoryList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_search_history, parent, false);
            holder = new ViewHolder();
            holder.textView = convertView.findViewById(R.id.history_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(searchHistoryList.get(position));
        return convertView;
    }

    static class ViewHolder {
        TextView textView;
    }
}
